﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Studentium.Util;

namespace Studentium
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
#if !DEBUG
            try
            {
#endif
                log4net.Config.XmlConfigurator.Configure();

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                MainForm mainForm = new MainForm();
                if (!mainForm.IsDisposed) 
                    Application.Run(mainForm);
#if !DEBUG
            }
            catch(Exception e)
            {
                Log.log(e);
                MessageBox.Show("Error! Check if database computer is running, restart application or contact application developer (dkrasikov@gmail.com)", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
#endif
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args)
        {
            try
            {
                Log.log("Unhandled exception!" + args.ExceptionObject, "ERROR");
            }
            finally
            {
                Application.Exit();
            }
        }
    }
}
